//
//  HELCourseDetailBottom.m
//  ViewFrameDemo
//
//  Created by wsj2015 on 2017/2/15.
//  Copyright © 2017年 Wecan Studio. All rights reserved.
//

#import "HELCourseDetailBottom.h"

#import "CBAutoScrollLabel.h"

@implementation HELCourseDetailBottom
{
   
    CBAutoScrollLabel *_scrollLabel;


}


- (IBAction)joinAction:(id)sender {
    
    if (self.joinBlock) {
        self.joinBlock();
    }
}

- (void)tellTheCurrentCourseStep:(NSString *)title isAble:(BOOL)isAble{
    
  
    UIButton *btn = [self viewWithTag:300];
    
    if (!isAble) {
        _scrollLabel.backgroundColor = [UIColor lightGrayColor];
        _scrollLabel.text = @"课程已参加，请点击目录开始学习";
        btn.enabled = NO;
    }else{
        btn.enabled = YES;
        _scrollLabel.text = title;
        
       
        CGFloat w = [title boundingRectWithSize:CGSizeMake(kScreenWidth, self.bounds.size.height) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:19]} context:nil].size.width;
        if (w>kScreenWidth - 10) {
          
          
        }
     
    }
    
}


- (void)update_animation{
  
//  CGRect frame = _scrollLabel.frame;
//    frame.origin.x -=2;
//    [UIView animateWithDuration:.2 delay:0 options:0 animations:^{
//        _scrollLabel.frame = frame;
//    } completion:^(BOOL finished) {
//        
//    }];
}


- (instancetype)initWithFrame:(CGRect)frame{
   
    if (self = [super initWithFrame: frame]) {
      
        
        UIButton *btn =[UIButton buttonWithType:UIButtonTypeCustom];
        [btn setTitle:@"" forState:UIControlStateNormal];
        [btn addTarget:self action:@selector(joinAction:) forControlEvents:UIControlEventTouchUpInside];
        btn.frame = frame;
        btn.tag = 300;
        [btn setBackgroundColor:[UIColor clearColor]];
        
        _scrollLabel = [CBAutoScrollLabel new];
        _scrollLabel.frame =  frame;
        _scrollLabel.backgroundColor = kMainColor;
        _scrollLabel.textColor = [UIColor whiteColor];
        _scrollLabel.font = [UIFont systemFontOfSize:19];
        _scrollLabel.textAlignment = NSTextAlignmentCenter;
        [self addSubview:_scrollLabel];
        
        [self addSubview:btn];
    }
    return self;

}


- (void)layoutSubviews{

    [super layoutSubviews];
    
    UIButton *btn = [self viewWithTag:300];
    
    btn.frame = CGRectMake(0, 0, kScreenWidth, 49);
    _scrollLabel.frame = btn.frame;
    
    

}


@end
